﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ITProject.Domain.Entities;

namespace ITProject.WebUI.Models.Project
{    
    public class ProjectReleaseViewModel
    {
        public string Name { get; set; }
        public string Description { get; set; }
        public string PlannedEndDate { get; set; }
        public string ReleaseStatus { get; set; }
        public StatusChangeViewModel[] ReleaseStatusChange { get; set; }

        public static ProjectReleaseViewModel[] Convert(Release[] release, StatusChange[][] releaseStatusChange, 
            string [][] releaseStatusChangesUserNames)
        {
            ProjectReleaseViewModel[] vmTab = new ProjectReleaseViewModel[release.Length];
            for (int i = 0; i < release.Length; i++)
            {
                vmTab[i] = new ProjectReleaseViewModel();
                vmTab[i].Name = release[i].Name;
                vmTab[i].Description = release[i].Description;
                vmTab[i].PlannedEndDate = release[i].PlannedEndDate.ToLongDateString();
                vmTab[i].ReleaseStatus = StatusName.ConvertFromByte(release[i].Status);
                vmTab[i].ReleaseStatusChange=new StatusChangeViewModel[releaseStatusChange[i].Length];
                for (int j = 0; j < releaseStatusChange[i].Length; j++)
                    vmTab[i].ReleaseStatusChange[j] = StatusChangeViewModel.Convert(releaseStatusChange[i][j],releaseStatusChangesUserNames[i][j]);
            }
            return vmTab;
        }
    }
}